﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;
namespace AutoBackupDatabase.DAL
{
    public class EMPLOYERDAL
    {
         private DbConnection conn;
         public EMPLOYERDAL()
        {
            conn = new DbConnection();
        }
         public List<EMPLOYERENT> GET_EMPLOYER_ALL()
         {
             string query = string.Format("exec GET_EMPLOYER_ALL ");
             DataTable ds = conn.executeGetQuery(query);
             List<EMPLOYERENT> List = new List<EMPLOYERENT>();
             try
             {
                 
                 foreach (DataRow item in ds.Rows)
                 {
                     EMPLOYERENT EMPLOYERent = new EMPLOYERENT();
                     EMPLOYERent.EMPLOYERID = int.Parse(item["EMPLOYERID"].ToString());
                     EMPLOYERent.FIRSTNAME = item["FIRSTNAME"].ToString();
                     EMPLOYERent.MIDDLENAME = item["MIDDLENAME"].ToString();
                     EMPLOYERent.LASTNAME = item["LASTNAME"].ToString();
                     EMPLOYERent.DOB = DateTime.Parse(item["DOB"].ToString());
                     EMPLOYERent.DATEWORK = DateTime.Parse(item["DATEWORK"].ToString());
                     EMPLOYERent.ADDRESS = item["ADDRESS"].ToString();
                     EMPLOYERent.FULLNAME = item["FULLNAME"].ToString();
                     EMPLOYERent.IDCARD = item["IDCARD"].ToString();
                     EMPLOYERent.DEPARTMENTID = item["DEPARTMENTID"].ToString();
                     EMPLOYERent.DEPARTMENTNAME = item["DEPARTMENTNAME"].ToString();

                     List.Add(EMPLOYERent);
                 }
                 return List;
             }
             catch (Exception)
             {

                 return List; 
             }
             
             
            

           
         }
         public bool INSERTEMPLOYER(EMPLOYERENT ent)
         {
             string query = "exec INSERTEMPLOYER  @FIRSTNAME ,@MIDDLENAME ,@LASTNAME,@FULLNAME ,@DOB ,@IDCARD ,@ADDRESS,@DEPARTMENTID,@DATEWORK";
             SqlParameter[] sqlParameters = new SqlParameter[9];
             sqlParameters[0] = new SqlParameter("@FIRSTNAME", SqlDbType.NVarChar);
             sqlParameters[0].Value = Convert.ToString(ent.FIRSTNAME);
             sqlParameters[1] = new SqlParameter("@MIDDLENAME", SqlDbType.NVarChar);
             sqlParameters[1].Value = Convert.ToString(ent.MIDDLENAME);

             sqlParameters[2] = new SqlParameter("@LASTNAME", SqlDbType.NVarChar);
             sqlParameters[2].Value = Convert.ToString(ent.LASTNAME);
             sqlParameters[3] = new SqlParameter("@FULLNAME", SqlDbType.NVarChar);
             sqlParameters[3].Value = Convert.ToString(ent.FULLNAME);

             sqlParameters[4] = new SqlParameter("@DOB", SqlDbType.DateTime);
             sqlParameters[4].Value = ent.DOB;
             sqlParameters[5] = new SqlParameter("@IDCARD", SqlDbType.VarChar);
             sqlParameters[5].Value = Convert.ToString(ent.IDCARD);

             sqlParameters[6] = new SqlParameter("@ADDRESS", SqlDbType.NVarChar);
             sqlParameters[6].Value = Convert.ToString(ent.ADDRESS);
             sqlParameters[7] = new SqlParameter("@DATEWORK", SqlDbType.DateTime);
             sqlParameters[7].Value = ent.DATEWORK;

             sqlParameters[8] = new SqlParameter("@DEPARTMENTID", SqlDbType.VarChar);
             sqlParameters[8].Value = Convert.ToString(ent.DEPARTMENTID);
            
            
             return conn.executeInsertQuery(query, sqlParameters);
         }
         public bool UPDATEEMPLOYERBYEMPLOYERID(EMPLOYERENT ent)
         {
             string query = "exec  UPDATEEMPLOYERBYEMPLOYERID @EMPLOYERID,@FIRSTNAME ,@MIDDLENAME ,@LASTNAME,@FULLNAME ,@DOB ,@IDCARD ,@ADDRESS,@DATEWORK,@DEPARTMENTID";
             SqlParameter[] sqlParameters = new SqlParameter[10];
             sqlParameters[0] = new SqlParameter("@EMPLOYERID", SqlDbType.Int);
             sqlParameters[0].Value = Convert.ToString(ent.EMPLOYERID);
             sqlParameters[1] = new SqlParameter("@FIRSTNAME", SqlDbType.NVarChar);
             sqlParameters[1].Value = Convert.ToString(ent.FIRSTNAME);
             sqlParameters[2] = new SqlParameter("@MIDDLENAME", SqlDbType.NVarChar);
             sqlParameters[2].Value = Convert.ToString(ent.MIDDLENAME);

             sqlParameters[3] = new SqlParameter("@LASTNAME", SqlDbType.NVarChar);
             sqlParameters[3].Value = Convert.ToString(ent.LASTNAME);
             sqlParameters[4] = new SqlParameter("@FULLNAME", SqlDbType.NVarChar);
             sqlParameters[4].Value = Convert.ToString(ent.FULLNAME);

             sqlParameters[5] = new SqlParameter("@DOB", SqlDbType.DateTime);
             sqlParameters[5].Value = Convert.ToString(ent.DOB);
             sqlParameters[6] = new SqlParameter("@IDCARD", SqlDbType.VarChar);
             sqlParameters[6].Value = Convert.ToString(ent.IDCARD);

             sqlParameters[7] = new SqlParameter("@ADDRESS", SqlDbType.NVarChar);
             sqlParameters[7].Value = Convert.ToString(ent.ADDRESS);
             sqlParameters[8] = new SqlParameter("@DATEWORK", SqlDbType.DateTime);
             sqlParameters[8].Value = Convert.ToString(ent.DATEWORK);

             sqlParameters[9] = new SqlParameter("@DEPARTMENTID", SqlDbType.VarChar);
             sqlParameters[9].Value = Convert.ToString(ent.DEPARTMENTID);

           

             return conn.executeUpdateQuery(query, sqlParameters);
         }
         public bool DELTELEEMPLOYERBYEMPLOYERID(EMPLOYERENT ent)
         {
             string query = "exec  DELTELEEMPLOYERBYEMPLOYERID @EMPLOYERID";
             SqlParameter[] sqlParameters = new SqlParameter[1];
             sqlParameters[0] = new SqlParameter("@EMPLOYERID", SqlDbType.VarChar);
             sqlParameters[0].Value = Convert.ToString(ent.EMPLOYERID);
             return conn.executeDeleteQuery(query, sqlParameters);
         }
    }
}
